package com.dongzili.demo.customer.fulltext.service;

import cn.hutool.core.thread.ExecutorBuilder;
import cn.hutool.core.thread.ThreadFactoryBuilder;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @描述：
 * @作者： 96511
 * @日期： 2025-01-05 17:31
 */
public class ExecutorUtils {

    private static final ExecutorService syncPool = ExecutorBuilder.create()
            .setCorePoolSize(Runtime.getRuntime().availableProcessors()-2)//初始20个线程
            .setMaxPoolSize(Runtime.getRuntime().availableProcessors()-2)//最大40个线程
//            .setWorkQueue(new LinkedBlockingQueue<>())
            .setWorkQueue(new ArrayBlockingQueue<>(10))
            .setKeepAliveTime(600, TimeUnit.SECONDS)//线程空闲后的最大存活时间
            .setThreadFactory(ThreadFactoryBuilder.create().setNamePrefix("sync-thread-").build())//设置线程前缀
            .build(); // 创建自定义线程池

    /**
     * 获取线程池
     */
    public static ExecutorService getPool() {
        return syncPool;
    }
}
